<template>
  <div id="App">
    <SearchPage :message="records" v-model="searchKeyword"></SearchPage>
    <XiangPage></XiangPage>
  </div>
</template>

<script>
import SearchPage from './components/SearchPage.vue'
import XiangPage from './components/XiangPage.vue'
export default {
  data () {
    return {
      searchKeyword: '', // 添加这个属性
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药'
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药'
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴'
        }
      ]
    }
  },
  components: {
    SearchPage,
    XiangPage
  },
  watch: {
    searchKeyword (newValue) {
      this.records = this.originalRecords.filter(item =>
        item.doctor.includes(newValue) // 根据搜索关键字过滤
      )
    }
  },
  mounted () {
    this.originalRecords = [...this.records] // 保存原始记录
  }
}
</script>

<style>
</style>
